#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct ac
{
	int i;
	char data[0];
};

int main()
{
    /*11c9:	f3 0f 1e fa          	endbr64 
    11cd:	55                   	push   %rbp
    11ce:	48 89 e5             	mov    %rsp,%rbp
    11d1:	48 83 ec 40          	sub    $0x40,%rsp
    11d5:	89 7d cc             	mov    %edi,-0x34(%rbp)
    11d8:	48 89 75 c0          	mov    %rsi,-0x40(%rbp)
    11dc:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    11e3:	00 00 
    11e5:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    11e9:	31 c0                	xor    %eax,%eax*/

    /*11eb:	48 c7 45 d8 00 00 00 	movq   $0x0,-0x28(%rbp) // (rpb-0x28)=0
    11f2:	00 */
	void *p = NULL;

    /*11f3:	48 b8 61 62 63 64 65 	movabs $0x6867666564636261,%rax
    11fa:	66 67 68 
    11fd:	48 89 45 ee          	mov    %rax,-0x12(%rbp)		// (rbp-0x12)="abcdefgh"
    1201:	66 c7 45 f6 69 00    	movw   $0x69,-0xa(%rbp)*/	// (rbp-0xa) ="i"
	char buf[10] = "abcdefghi";	

    /*1207:	bf 0e 00 00 00       	mov    $0xe,%edi			// edi=14
    120c:	e8 bf fe ff ff       	callq  10d0 <malloc@plt>
    1211:	48 89 45 e0          	mov    %rax,-0x20(%rbp)*/	// rax=malloc
	struct ac * info = (struct ac *)malloc(sizeof(struct ac) + 10);

    /*1215:	48 8b 45 e0          	mov    -0x20(%rbp),%rax		// rax=malloc
    1219:	c7 00 09 00 00 00    	movl   $0x9,(%rax)*/		// (rax)=9
	info->i = 9;

    /*121f:	48 8b 45 e0          	mov    -0x20(%rbp),%rax		// rax=malloc
    1223:	48 83 c0 04          	add    $0x4,%rax			// rax=rax+4
    1227:	48 89 45 d8          	mov    %rax,-0x28(%rbp)*/	// (rbp-0x28)=malloc+4
	p = (void*)info->data;

    /*122b:	be 04 00 00 00       	mov    $0x4,%esi
    1230:	48 8d 3d cd 0d 00 00 	lea    0xdcd(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    1237:	b8 00 00 00 00       	mov    $0x0,%eax
    123c:	e8 7f fe ff ff       	callq  10c0 <printf@plt>*/
	printf("%d\n", 4);

    /*1241:	48 8b 55 d8          	mov    -0x28(%rbp),%rdx		// rdx=p
    1245:	48 8b 45 e0          	mov    -0x20(%rbp),%rax		// rax=info
    1249:	48 89 c6             	mov    %rax,%rsi
    124c:	48 8d 3d b5 0d 00 00 	lea    0xdb5(%rip),%rdi        # 2008 <_IO_stdin_used+0x8>
    1253:	b8 00 00 00 00       	mov    $0x0,%eax
    1258:	e8 63 fe ff ff       	callq  10c0 <printf@plt>*/
	printf("info address:%p\n", info, p);

    /*125d:	48 8b 45 d8          	mov    -0x28(%rbp),%rax		// rdx=p
    1261:	48 89 c6             	mov    %rax,%rsi
    1264:	48 8d 3d ae 0d 00 00 	lea    0xdae(%rip),%rdi        # 2019 <_IO_stdin_used+0x19>
    126b:	b8 00 00 00 00       	mov    $0x0,%eax
    1270:	e8 4b fe ff ff       	callq  10c0 <printf@plt>*/
	printf("   p address:%p\n", p);

    /*1275:	48 8d 45 d8          	lea    -0x28(%rbp),%rax		// rax=&p
    1279:	48 89 c6             	mov    %rax,%rsi
    127c:	48 8d 3d 96 0d 00 00 	lea    0xd96(%rip),%rdi        # 2019 <_IO_stdin_used+0x19>
    1283:	b8 00 00 00 00       	mov    $0x0,%eax
    1288:	e8 33 fe ff ff       	callq  10c0 <printf@plt>*/
	printf("   p address:%p\n", &p);

    /*128d:	48 8b 45 e0          	mov    -0x20(%rbp),%rax		// rax=info
    1291:	8b 00                	mov    (%rax),%eax			// eax=*info
    1293:	48 63 d0             	movslq %eax,%rdx			// rdx=info->i
    1296:	48 8b 45 d8          	mov    -0x28(%rbp),%rax		// rax=p
    129a:	48 8d 4d ee          	lea    -0x12(%rbp),%rcx		// rcx=buf
    129e:	48 89 ce             	mov    %rcx,%rsi			// rsi=buf
    12a1:	48 89 c7             	mov    %rax,%rdi			// rdi=p
    12a4:	e8 e7 fd ff ff       	callq  1090 <strncpy@plt>*/
	strncpy((char*)p, buf, info->i);

    /*12a9:	48 8b 45 d8          	mov    -0x28(%rbp),%rax		// rax=p
    12ad:	48 89 c7             	mov    %rax,%rdi
    12b0:	e8 eb fd ff ff       	callq  10a0 <puts@plt>*/
	printf("%s\n", (char*)p);

    /*12b5:	b8 00 00 00 00       	mov    $0x0,%eax
    12ba:	48 8b 4d f8          	mov    -0x8(%rbp),%rcx
    12be:	64 48 33 0c 25 28 00 	xor    %fs:0x28,%rcx
    12c5:	00 00 
    12c7:	74 05                	je     12ce <main+0x105>
    12c9:	e8 e2 fd ff ff       	callq  10b0 <__stack_chk_fail@plt>
    12ce:	c9                   	leaveq 
    12cf:	c3                   	retq   */
	return 0;
}
